import api from './index'

export interface Submission {
  id: number
  homework_id: number
  problem_id: number
  student_id: number
  code: string
  status: 'Pending' | 'AC' | 'WA' | 'RE' | 'TLE'
  submit_time: string
  problem?: Problem
  homework?: Homework
  student?: User
}

export interface Problem {
  id: number
  title: string
  description: string
  type: string
}

export interface Homework {
  id: number
  title: string
  description?: string
}

export interface User {
  id: number
  username: string
  role: string
}

export interface CreateSubmissionRequest {
  homework_id: number
  problem_id: number
  code: string
}

export const submissionsApi = {
  // 提交代码
  createSubmission(data: CreateSubmissionRequest): Promise<Submission> {
    return api.post('/submissions', data)
  },

  // 获取提交详情
  getSubmission(id: number): Promise<Submission> {
    return api.get(`/submissions/${id}`)
  },

  // 获取作业的所有提交
  getSubmissionsByHomework(homeworkId: number): Promise<Submission[]> {
    return api.get(`/submissions/homework/${homeworkId}`)
  },

  // 获取我的提交
  getMySubmissions(): Promise<Submission[]> {
    return api.get('/submissions/my-submissions')
  }
}
